//
//  SetingViewController.m
//  Arts1
//
//  Created by lanou on 15/9/7.
//  Copyright (c) 2015年 Arts1. All rights reserved.
//

#import "SetingViewController.h"
#import "AllHeader.h"
#import "PersonalViewController.h"
#import "HomeListViewController.h"
#import "ServiceTermsViewController.h"


@interface SetingViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic ,strong) UITableView *mainTableView;

@property (nonatomic ,strong) NSArray *dataSource;

@property (nonatomic ,strong) NSString *loginState;

@end

@implementation SetingViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.title = @"设置";
    // Do any additional setup after loading the view.
    
    [self creactData];
    
    [self creactTableView];
}

- (void)creactData
{
    _dataSource = @[@[@"个人设置",@"系统设置",@"清理缓存"],@[@"意见反馈",@"服务条款"],@"退出登录"];
}

//创建设置页面视图
- (void)creactTableView
{
    _mainTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:(UITableViewStyleGrouped)];
    _mainTableView.backgroundColor = kCustomColor(250, 250, 250, 1.0);
    
    _mainTableView.delegate = self;
    _mainTableView.dataSource = self;
    
    _mainTableView.bounces = NO;
    
    [self.view addSubview:_mainTableView];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
    {
        return 3;
    }
    else if (section == 1)
    {
        return 2;
    }
    else
    {
        return 1;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 30;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"cell"];
    }
    
    switch (indexPath.section)
    {
        case 0:
            cell.textLabel.text = _dataSource[0][indexPath.row];
            cell.textLabel.font = [UIFont systemFontOfSize:14];
            break;
        case 1:
            cell.textLabel.text = _dataSource[1][indexPath.row];
            cell.textLabel.font = [UIFont systemFontOfSize:14];
            break;
        case 2:
        {
            cell.textLabel.text = _dataSource[2];
            cell.textLabel.font = [UIFont systemFontOfSize:18];
            cell.textLabel.textAlignment = NSTextAlignmentCenter;
        }
            break;
            
        default:
            break;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section)
    {
        case 0://第一个分区
        {
            if (indexPath.row == 0)//个人设置
            {
                NSLog(@"个人设置");
                // 进入个人设置页面
                PersonalViewController *personVC = [[PersonalViewController alloc] init];
                [self.navigationController pushViewController:personVC animated:YES];
            }
            else if (indexPath.row == 1)//系统设置
            {
                NSLog(@"系统设置");
            }
            else if (indexPath.row == 2)//清楚缓存
            {
                NSLog(@"清楚缓存");
            }
        }
            break;
        case 1://第二个分区
        {
            if (indexPath.row == 0)//帮助中心
            {
                NSLog(@"帮助中心");
            }
            else if (indexPath.row == 1)//服务条款
            {
                NSLog(@"服务条款");
                //  服务条款
                ServiceTermsViewController *serviewVC = [[ServiceTermsViewController alloc] init];
                [self.navigationController pushViewController:serviewVC animated:YES];
            }
        }

            break;
        case 2://第三个分区
        {
            [[NSUserDefaults standardUserDefaults] setObject:nil forKey:@"dataForKeyAndUid"];
            [[NSUserDefaults standardUserDefaults] setObject:nil forKey:@"weixinLogin"];
            
            self.tabBarController.selectedIndex = 2;
           UINavigationController *homeNavi = (UINavigationController *)self.tabBarController.viewControllers[2];
            
            HomeListViewController *homeLVC = (HomeListViewController *)homeNavi.viewControllers[0];
            [homeLVC createLoginView];
            
            //退出登录
            NSLog(@"退出登录");
        }
            break;
            
        default:
            break;
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end
